package com.pig4cloud.pigx.strategy.websocket.app.message;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.pig4cloud.pigx.common.core.util.SpringContextHolder;
import org.springframework.web.socket.TextMessage;

/**
 * 开放式 api - webSocket 发送消息
 *
 */
public class SendMessage {

	public static TextMessage getTextMessage(Object object) {
		try {
			ObjectMapper objectMapper = SpringContextHolder.getBean(ObjectMapper.class);
			String asString = objectMapper.writeValueAsString(object);
			return new TextMessage(asString);
		} catch (Exception e) {
			return new TextMessage((CharSequence) object);
		}
	}
}
